<?php

namespace App\Admin\Controllers;

use App\Admin\Grid\NGrid;
use App\Library\Traits\AdminControllerTrait;
use App\Models\AddressModel;
use App\Models\AreaModel;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Grid\Filter;
use Encore\Admin\Tree;
use Encore\Admin\Layout\Content;

class AreaController extends AdminController
{
    use AdminControllerTrait;

    protected $title = '行政区划';

    private array $statusArr = [0 => '不可用', 1 => '可用'];

    /**
     * grid
     * @return Grid
     */
    public function grid(): Grid
    {
        $grid = new Grid(new AreaModel);
        $grid->filter(function (Filter $filter) {
            $filter->disableIdFilter();
            $filter->column(1 / 2, function (Filter $filter) {
                $filter->equal('id', 'ID')->integer();
                $filter->equal('parent_id', '父级')->integer();
                //$filter->equal('status', '父级')->select($this->statusArr);
            });
            $filter->column(1 / 2, function (Filter $filter) {
                $filter->equal('level', '等级')->integer();
                $filter->like('name', '名称');
            });
        });
        $grid->column('id', 'ID')->sortable();
        //$grid->column('status', '状态')->switch($this->statusArr);
        $grid->column('level', '等级');
        $grid->column('code');
        $grid->column('parent_id', '父级');
        $grid->column('name', '名称');
        return $grid;
    }

    /**
     * form
     * @return Form
     */
    public function form(): Form
    {
        $form = new Form(new AreaModel);
        $form->radio('status')->options($this->statusArr)->required();
        $form->text('name')->required();
        return $form;
    }
}
